package com.leeon.thread;

import static net.mindview.util.Print.print;

import java.util.concurrent.TimeUnit;

class Daemon implements Runnable{

	private Thread[] ts = new Thread[10];
	
	@Override
	public void run() {
		for(int i = 0; i < ts.length; i++) {
			ts[i] = new Thread(new DaemonSpawn());
			ts[i].start();
			print("DaemonSpawn " + i + " started.");
		}
		for (int i = 0; i < ts.length; i++) {
			print("ts[" + i + "].lenght = " + ts[i].isDaemon() + ".");
		}
		while (true) {
			Thread.yield();
		}
	}
	
}

class DaemonSpawn implements Runnable{

	@Override
	public void run() {
		while(true) {
			Thread.yield();
		}
	}
	
}

public class Daemons{

	public static void main(String[] args) throws InterruptedException {
		Thread d = new Thread(new Daemon());
		d.setDaemon(true);
		d.start();
		print("d.isDaemon = " + d.isDaemon() + ",");
		TimeUnit.SECONDS.sleep(1);
	}
	
}
